package ext.csc.component.numbergen.number;

import java.sql.ResultSet;

import ext.csc.component.numbergen.bean.PropertiesBean;
import ext.csc.component.numbergen.bean.RequestInfoContained;
import ext.csc.component.numbergen.connection.DBConn;

public class NumberRegister {
	private PropertiesBean pb;
	private FormatedNumber fnumber;
	public static final NumberRegisterManager manager;
	
	public NumberRegister(PropertiesBean pb, FormatedNumber fnumber){
		this.pb = pb;
		this.fnumber = fnumber;
	}
	
	static{
		manager = new NumberRegisterManager ();
	}
	
	public void registerNumbers(int volumn){
		Sequence seq;
		GeneratedNumber gnumber;
		for (int i = 0; i < volumn; i++) {
			try {
				seq = new Sequence(pb,fnumber);
				gnumber = new GeneratedNumber();
				String formatedNumber = fnumber.getValue();
				
				gnumber.setNumber(formatedNumber.replaceAll("<Seq>", seq.getValue()));
				gnumber.setClasspath(fnumber.getClassification().getObjectclasspath());
				gnumber.setRequestor(fnumber.getRequestor());
				gnumber.setDatetime(fnumber.getDateTime());
				gnumber.setFlag(NumberManager.GENERATED_FLAG);
				gnumber.setRequestdesc(fnumber.getRequestDesc());
				gnumber.setObjectname(fnumber.getClassification().getObjectname());
				gnumber.setSeq(seq.getIValue());
				gnumber.setCanceldesc("");
				
				manager.registerOneNumber((NumberInfoContained)gnumber,(RequestInfoContained)gnumber);
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
		}
	}
}
